#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#define N 100
int main()
{
	int K = 0;
	int af = 0;
	int i = 0;
	char arr[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
	int num = 0;
	int a[N] = { 0 };
	scanf("%d", &K);
	scanf("%d", &af);
	while (K != 0)
	{
		a[i++] = K % af;
		K = K / af;
	}
	for (i--; i >= 0; i--)
	{
		printf("%c", arr[a[i]]);
	}
	return 0;
}